:: this batch file periodically checks the free space on drive Y: (which is a 
:: shared directory on Ma-fs, and hence is effectively the same as the free 
:: space on Ma-fs). If there is less than 5Gb, it emails me to let me know. Ace. 
::@echo off
:: schtasks /Create /tn "JoshHelloWorld" /tr "Z:\josh-phd-code\batch\helloworld.bat" /sc ONCE /sd 21/04/2011 /st 11:15

:: read in the free disk space (in bytes). Note the ^s for the comma & pipe.
@echo off
for /f "delims=" %%b in ('freedisk /d Y: 15Gb') do @set freedisk=%%b

if "%freedisk:~0,7%"=="SUCCESS" (
    goto :eof
)

::find actual free disk space
for /f "delims=" %%b in ('freedisk /d Y: ^| grep -o -E [0-9^,]+') do @set freespace=%%b
:: ::remove commas
:: set freespace=%freespace:,=%

set jcb_email_to=jcb91@cam.ac.uk
set jcb_email_from=masimulation1@gmail.com
set jcb_email_pw=beaming2009
set jcb_blatopts=-server 127.0.0.1 -to %jcb_email_to% -f %jcb_email_from% -u %jcb_email_from% -pw %jcb_email_pw%
set body="Filespace on server Ma-fs is running low! Only %freespace% bytes remain!"
set subject="Low filespace on Ma-fs!"
blat -subject %subject% -body %body% %jcb_blatopts% 
:: end with empty line